<template>
	<div class="website-activity-wrap" >
		<el-form :model="formData"  ref="ruleForm" label-width="100px">
			<el-form-item label="广告：" >
				<el-input style="width: 60%;" size="small" v-model="formData.advertising" placeholder="请输入" clearable></el-input>
			</el-form-item>
			<el-form-item label="电话号码：" >
				<el-input style="width: 60%;" size="small" v-model="formData.phone" placeholder="请输入" clearable></el-input>
			</el-form-item>
			<el-form-item label="客服二维码：" prop="wechat_qr_code">
				<el-input class="hidden" v-model="formData.wechat_qr_code"></el-input>
				<img-upload :headerImage.sync="formData.wechat_qr_code"></img-upload>
			</el-form-item>
			<el-form-item v-if="!role_id" >
				<el-button type="primary" size="small" @click="save" >保存</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import imgUpload from '@/components/img-upload'
	import { SITE_INFO } from '@/api/crm'
	export default {
		components: {
			imgUpload
		},
		data() {
			const role_id = +localStorage.getItem('role_id')
			return{
				role_id,
				formData: {
					advertising: '',
					phone: '',
					wechat_qr_code: ''
				}
			}
		},
		mounted() {
			
			this.getInfo()
		},
		methods: {
			getInfo() {
				this.$http.get(SITE_INFO)
					.then(res => {
						if(res.data) {
							this.formData = res.data
						}
					})
			},
			save() {
				const {
					advertising,
					phone,
					wechat_qr_code
				} = this.formData
				let params = {}
					params['wechat_qr_code'] = wechat_qr_code
					params['phone'] = phone
					params['advertising'] = advertising
				this.$http.put(SITE_INFO, params)
					.then(() => {
						this.$message({
							type: 'success',
							message: '设置成功'
						})
					})
			}
		}
		
	}
</script>

<style lang="scss" >
	.website-activity-wrap{
		
	}
</style>
